package com.ad.pet.app.collect;

import android.app.Activity;

import com.ad.pet.api.ApiService;
import com.ad.pet.app.RxDisposable;
import com.ad.pet.common.data.http.AppSubscriber;
import com.ad.pet.common.data.injector.PerActivity;
import com.ad.pet.common.structure.mvp.AbsBasePresenter;
import com.ad.pet.models.remote.account.order.OrderType;

import java.util.List;

import javax.inject.Inject;

/**
 * Created by SEELE on 2018/7/4.
 */
@PerActivity
public class CollectPresenter  extends AbsBasePresenter implements CollecContract.Presenter{

    private ApiService mApiService;
    private CollecContract.View mView;

    private Activity mActivity;

    private RxDisposable mRxDisposable;

    @Inject
    public CollectPresenter(ApiService apiService,
                               Activity activity, RxDisposable rxDisposable) {
        mApiService = apiService;
        mActivity = activity;
        mRxDisposable = rxDisposable;
    }

    @Override
    public void onCreate(CollecContract.View view) {
        this.mView = view;
    }

    @Override
    public void onDestroy() {
        if (mRxDisposable!=null)
            mRxDisposable.clear();
        if (mActivity != null) mActivity = null;
        mView = null;
    }





    @Override
    public void getCollectGoods(String type) {
        mRxDisposable.add(mApiService.collect_item_list(type)
                .subscribe(new AppSubscriber<List<OrderType>>(mView) {
                    @Override
                    public void next(List<OrderType> list) {
                        mView.getCollectGoodsSuccess(list);
                    }
                }));
    }


}
